##############################################################
#Figure D4: First Stage (Pooled) in HRS High Risk Areas
##############################################################

data <- read.dta13("U:/temp/toplot_descriptive1.dta")

df <- data %>% filter(!is.na(state)) %>% group_by(stateid) %>% 
  summarise_at(vars(risk, distance), funs(mean(.,na.rm = TRUE)))

df


ggplot(data[data$distance<1000,], aes(distance, risk)) + 
  stat_smooth(method="lm", fill="grey50", size=2,alpha=0.2, color="black") + 
  stat_smooth(method="loess", fill="grey80", size=1,alpha=0.2, linetype="dashed",color="grey") + 
  coord_cartesian(ylim= c(4.3,5.3))  + ylab("Risk Aversion") + xlab("Distance (km)") 

ggsave("U:/export/figd4.pdf")
